package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import com.itheima.domain.vo.MovementVo;
import com.itheima.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {
    @Autowired
    private MovementManager movementManager;

    //发布动态
    @PostMapping("/movements")
    public Map saveMovement(Movement movement , MultipartFile[] imageContent) throws IOException {
        //保存动态
        movementManager.saveMovement(movement ,imageContent );
        return null;
    }
    //查询好友动态
    @GetMapping("/movements")
    public PageBeanVo findFriendMovements(@RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
                                          @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize) {

        return movementManager.findFriendMovements(pageNumber , pageSize);
    }
    //查询我的个人动态 , 还可以其他的接口使用
    @GetMapping("/movements/all")
    public PageBeanVo findMyMovement(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize,
            Long userId
    ) {
        //查询数据
        return movementManager.findMyMovement(pageNumber,pageSize, userId);
    }


    //查询推荐动态
    @GetMapping("/movements/recommend")
    public PageBeanVo findRecommendMovement(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize
    ) {
        //查询数据
        return movementManager.findRecommendMovement(pageNumber,pageSize);
    }

    //点赞
    @GetMapping("/movements/{id}/like")
    public Integer saveMovementLike(
            @PathVariable(value = "id") String movementId
    ) {
        //查询数据
        return movementManager.saveMovementLike(movementId);
    }
    //取消点赞
    @GetMapping("/movements/{id}/dislike")
    public Integer deleteMovementLike(
            @PathVariable(value = "id") String movementId
    ) {
        //查询数据
        return movementManager.deleteMovementLike(movementId);
    }

    //单条动态
    @GetMapping("/movements/{id}")
    public MovementVo findMovementById(
            @PathVariable(value = "id") String movementId
    ) {
        //查询数据
        return movementManager.findMovementById(movementId);
    }
    //评论列表
    @GetMapping("/comments")
    public PageBeanVo findMovementComment(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize,
            String movementId
    ) {
        //查询数据
        return movementManager.findMovementComment(pageNumber, pageSize , movementId);
    }

    //动态的评论
    @PostMapping("/comments")
    public Map saveMovementComment(
            @RequestBody Map<String, String> map
    ) {
        String movementId = map.get("movementId");
        String content = map.get("comment");
        //查询数据
        return movementManager.saveMovementComment(movementId,content);
    }



    //喜欢统计
    @GetMapping("/messages/loves")
    public PageBeanVo findLoveComment(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize
    ) {
        int commentType = 3;
        //查询数据
        return movementManager.findCommentByCommentType(pageNumber,pageSize, commentType);
    }

    //点赞统计
    @GetMapping("/messages/likes")
    public PageBeanVo findLikeComment(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize
    ) {
        int commentType = 1;
        //查询数据
        return movementManager.findCommentByCommentType(pageNumber,pageSize, commentType);
    }


    //动态统计
    @GetMapping("/messages/comments")
    public PageBeanVo findComment(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pagesize" )Integer pageSize
    ) {
        int commentType = 2;
        //查询数据
        return movementManager.findCommentByCommentType(pageNumber,pageSize , commentType);
    }
}
